'use strict';

/**
 * @ngdoc directive
 * @name jgappApp.directive:comment
 * @description
 * # comment
 */
angular.module('jgappApp')
    .directive('comment', ["DataService", "Util", "openApi", function(DataService, Util, openApi) {
        return {
            scope: {
                data: "=commentObj",
            },
            template: '<div class="commentdirective">' +
                '<div class="comment-header cl lh30">' +
                '填写评论 <p class="fr c-blue submit" ng-click="submit()"> 发送 </p></div> ' +
                '<textarea ng-model="comment"></textarea> </div>',
            restrict: 'E',
            link: function postLink(scope, element, attrs) {
                // element.text('this is the comment directive');
                scope.submit = function() {
                    var url = openApi.addForworklog;
                    if (!this.comment) {
                        Util.Toast("请输入评论内容")
                        return;
                    }
                    var param = {};
                    param.refId = attrs.pkId
                    param.content = this.comment
                    if (attrs.commenttype == "weekly") {
                        url = openApi.addForworkweekly
                    } else if (attrs.commenttype == "task") {
                        url = openApi.addForWorktask
                    }
                    DataService.getData(url, param).then(function(data, success) {
                        Util.Toast("提交评论成功")
                        this.data.push(data);
                        this.comment = "";
                    }.bind(this))
                }
            }
        };
    }]);
